package com.qf.controller;

import com.qf.service.DtsAccountTraceService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 佣金管理
 * @author bss
 * @version V1.0
 * @Project maven
 * @Package com.qf.controller
 * @Description:
 * @Date 2022/10/15 20:09
 */
@RestController
@RequestMapping("/admin/brokerage")
public class AdminBrokerageController {

    @Autowired
    DtsAccountTraceService accountTraceService;

    @GetMapping("/list")
    public Object list(@RequestParam(value = "page",required = false, defaultValue = "1") Integer page,
                       @RequestParam(value = "limit",required = false, defaultValue = "20")Integer limit,
                       @RequestParam(value = "sort",required = false, defaultValue = "add_time")String sort,
                       @RequestParam(value = "order",required = false, defaultValue = "desc")String order,
                       @RequestParam(value = "username",required = false)String username,
                       @RequestParam(value = "mobile",required = false)String mobile,
                       String... statusArray){
//       &username=1&mobile=1&statusArray[]=0&sort=add_time&order=desc   statusArray[]
        System.out.println(sort);
        System.out.println(username);
        System.out.println(mobile);
        System.out.println(statusArray);
        Map<String, Object> data = accountTraceService.selectByPage(page,limit,sort,order,username,mobile,statusArray);

        return ResponseUtil.ok(data);
    }


    @PostMapping("/approve")
    public Object approve(@RequestBody Map<String,Object> map){
//        {id: 1, status: 1, traceMsg: "111"}
        int id = Integer.parseInt(String.valueOf(map.get("id")));
        int status = Integer.parseInt(String.valueOf(map.get("status")));
        String traceMsg = (String) map.get("traceMsg");

        accountTraceService.updateAccountTraceStatus(id,status,traceMsg);

        return ResponseUtil.ok();
    }
}
